﻿<!-- Copyright 2012-2017 Dmitry Kischenko

Licensed under the Apache License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
express or implied. 
See the License for the specific language governing permissions and 
limitations under the License. -->
<Window x:Class="xFunc.Views.VariableView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:views="clr-namespace:xFunc.Views"
        xmlns:res="clr-namespace:xFunc.Resources"
        xmlns:exps="clr-namespace:xFunc.Maths.Expressions.Collections;assembly=xFunc.Maths"
        Title="{x:Static res:Resource.VariablesTitle}" Width="220" Height="280"
        ShowInTaskbar="False">
    <Window.CommandBindings>
        <CommandBinding Command="views:VariableView.AddCommand" Executed="AddCommand_Executed" />
        <CommandBinding Command="views:VariableView.EditCommand" Executed="EditCommand_Executed" CanExecute="EditCommand_CanExecute" />
        <CommandBinding Command="views:VariableView.DeleteCommand" Executed="DeleteCommand_Executed" CanExecute="DeleteCommand_CanExecute" />
        <CommandBinding Command="views:VariableView.RefreshCommand" Executed="RefreshCommand_Executed" />
    </Window.CommandBindings>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.Triggers>
            <EventTrigger RoutedEvent="MouseEnter">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="grid" Storyboard.TargetProperty="Height" To="39" Duration="0:0:0.15" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
            <EventTrigger RoutedEvent="MouseLeave">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="grid" Storyboard.TargetProperty="Height" To="0" Duration="0:0:0.15" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Grid.Triggers>

        <ListView x:Name="varList" Grid.Row="0" ItemsSource="{Binding}">
            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Expander IsExpanded="True">
                                            <Expander.Header>
                                                <TextBlock Foreground="#FF27276C" FontWeight="Medium" Text="{Binding Path=Name}" />
                                            </Expander.Header>
                                            <Expander.Content>
                                                <ItemsPresenter />
                                            </Expander.Content>
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </ListView.GroupStyle>
            <ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=Type}">
                            <DataTrigger.Value>
                                <exps:ParameterType>Constant</exps:ParameterType>
                            </DataTrigger.Value>
                            <Setter Property="Foreground" Value="Gray" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=Type}">
                            <DataTrigger.Value>
                                <exps:ParameterType>ReadOnly</exps:ParameterType>
                            </DataTrigger.Value>
                            <Setter Property="Foreground" Value="Gray" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="{x:Static res:Resource.VarNameHeader}">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Path=Variable}" TextAlignment="Center" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="{x:Static res:Resource.VarValueHeader}" DisplayMemberBinding="{Binding Path=Value}" />
                </GridView>
            </ListView.View>
        </ListView>
        <Grid x:Name="grid" Grid.Row="1" Background="#FFEFEFEF" Height="0">
            <Grid.Resources>
                <Style TargetType="{x:Type Button}">
                    <Setter Property="Width" Value="24" />
                    <Setter Property="Height" Value="24" />
                    <Setter Property="HorizontalAlignment" Value="Left" />
                    <Setter Property="VerticalAlignment" Value="Center" />
                </Style>
            </Grid.Resources>

            <Button Margin="10,0,0,0" Command="views:VariableView.AddCommand">
                <Image Source="..\Images\Add.png" />
            </Button>
            <Button Margin="42,0,0,0" Command="views:VariableView.EditCommand">
                <Image Source="..\Images\Edit.png" />
            </Button>
            <Button Margin="74,0,0,0" Command="views:VariableView.DeleteCommand">
                <Image Source="..\Images\Remove.png" />
            </Button>
            <Button Margin="106,0,0,0" Command="views:VariableView.RefreshCommand">
                <Image Source="..\Images\Refresh.png" />
            </Button>
        </Grid>
    </Grid>
</Window>
